package array

import "strconv"

// 数字序列 01234567891011121314151617181920... 求第n位对应的数字

// 迭代+求整

func FindNthDigit(n int) int {
	digit := 1
	start := 1
	count := 9
	for n > count {
		n -= count
		digit++
		start += 10
		count = digit * start * 9
	}
	num := start + (n-1)/digit
	index := (n - 1) % digit
	numStr := strconv.Itoa(num)
	return int(numStr[index] - '0')
}
